package com.ysd.repository;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.ysd.entity.Roles;

public interface RolesRepository extends JpaRepository<Roles, String> ,JpaSpecificationExecutor<Roles> {
	/**
	 * 向中间表添加角色和用户的
	 * @param userid
	 * @param roleid
	 */
	@Modifying
	@Query(value = "insert into userroles VALUES(?1,?2)", nativeQuery = true)
	@Transactional
	void saveUserrole(String userid, String roleid);

	/**
	 * 删除角色
	 * @param uId
	 * @param rId
	 */
	@Modifying
	@Query(value = "delete from userroles where userid = ?1 and roleid = ?2", nativeQuery = true)
	@Transactional
	void delUserrole(String userid, String roleid);
}
